<?php
namespace app\index\service;


use app\index\model\DeviceJieModel;
use app\index\model\DeviceJinModel;
use app\index\model\DeviceLinModel;
use app\index\model\DeviceTuiModel;
use app\index\model\DeviceYunModel;

class DeviceService extends CommonService
{

    public function create_device_jin_number(){
        $tou = 'JC';
        $daystr = substr(date("Ymd"), 2);
        $number = DeviceJinModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }


    public function create_device_yun_number(){
        $tou = 'YXJL';
        $daystr = substr(date("Ymd"), 2);
        $number = DeviceYunModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_device_tui_number(){
        $tou = 'TCDJ';
        $daystr = substr(date("Ymd"), 2);
        $number = DeviceTuiModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_device_jie_number(){
        $tou = 'ZLJS';
        $daystr = substr(date("Ymd"), 2);
        $number = DeviceJieModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_device_lin_number(){
        $tou = 'LSJXDJ';
        $daystr = substr(date("Ymd"), 2);
        $number = DeviceLinModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

}
